import axios from 'axios'
//import router from '../../router/router.js'
const book = {
    state: {
        bookLists: [],
        choBookList:[]
    },
    mutations: {
        setBookMsg(state,lists){
            state.bookLists = lists
        },
        setChoBook(state,list){
            state.choBookList = list
        },
        deleteBookItem(state,id){
            state.choBookList = state.choBookList.filter(val => val.id != id)
        }
    },
    actions: {
        getBookList({commit},type){
            if(type){
                type = type
            }else{
                type = ''
            }
            axios.get('/bookmsg?transform=1&order=id&filter=bookType,cs,'+type)
            .then(res => {
                console.log(res)
                commit('setBookMsg', res.data.bookmsg)
            })
            .catch(err => {
                
            })
        },
        addBookItem({commit},{obj,router}){
            return axios.post('/bookmsg',obj)
            .then(res => {
                console.log(res)
                if(res.data){
                    return res.data
                    //router.push('/home/book/list')
                }
            })
            .catch(err => {

            })
        }
    },
    
}

export default book